package com.wyz.saas.common.view

import android.content.Context
import android.util.AttributeSet
import com.bumptech.glide.RequestManager
import com.wyz.saas.common.R
import de.hdodenhof.circleimageview.CircleImageView


class PortraitView : CircleImageView {

    constructor(
        context: Context
    ) : super(context)

    constructor(
        context: Context,
        attrs: AttributeSet?
    ) : super(context, attrs)

    constructor(
        context: Context,
        attrs: AttributeSet?,
        defStyle: Int
    ) : super(context, attrs, defStyle)



    fun setup(manager: RequestManager, url: String?) {
        setup(manager, R.drawable.default_portrait, url)
    }


    fun setup(manager: RequestManager, resourceId: Int, urlfinal: String?) {
        val url = urlfinal ?:""
        manager.load(url)
            .placeholder(resourceId)
            .centerCrop()
            .dontAnimate() // CircleImageView 控件中不能使用渐变动画，会导致显示延迟
            .into(this)
    }
}